package com.ruoyi.web.controller.demo;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.page.TD;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.system.service.impl.SysUserServiceImpl;
import com.ruoyi.web.controller.demo.domain.TestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * demo
 */
@RestController
@RequestMapping("/testDemo")
@Api(value = "testDemo",tags = "测试")
public class TestDemoController extends BaseController {

    @Autowired
    private SysLoginService loginService;

    @Autowired
    private SysUserServiceImpl userService;

   /**
     * 登录方法
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    @ApiOperation("微信登录")
    public AjaxResult login(@RequestBody LoginBody loginBody)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.wxLogin(loginBody.getUsername());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    /**
     * 获取用户列表
     */
    @ApiOperation("获取用户列表")
    @GetMapping("/list")
    public TD<SysUser> list(SysUser sysUser) {
        startPage();
        List<SysUser> list = userService.selectUserList(sysUser);
        return getTD(list);
    }

    @ApiOperation("单体查询")
    @GetMapping("/getUser")
    public R<TestUser> getUser(TestUser testUser1) {
        TestUser testUser = new TestUser();
        testUser.setDeptId(1L);
        return R.success(testUser);
    }
}
